package com.xhl.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;

public class DateCode {
    public static String setCode() {
        Calendar cal = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println(sdf.format(cal.getTime()));
        int year = cal.get(Calendar.YEAR);
        // 比当前月份少1
        int month = cal.get(Calendar.MONTH) + 1;
        // date表示日期，day表示天数，所以date与day_of_month相同
        int date = cal.get(Calendar.DATE);
        int firstDay = cal.getFirstDayOfWeek();
        // public final static int SUNDAY = 1;表示一周开始的第一天为周日
        int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
        int dayOfYear = cal.get(Calendar.DAY_OF_YEAR);
        int hour = cal.get(Calendar.HOUR);
        int minute = cal.get(Calendar.MINUTE);
        int second = cal.get(Calendar.SECOND);
        int millisecond = cal.get(Calendar.MILLISECOND);
//		System.out.println("现在的年份为:" + year);
//		System.out.println("现在的月份为:" + month);
//		System.out.println("现在的号为:" + date);
//		System.out.println("现在是星期:" + dayOfWeek);
//		System.out.println("现在过了的天数为:" + dayOfYear);
//		System.out.println("现在几点:" + hour);
//		System.out.println("现在几分:" + minute);
//		System.out.println("现在几秒:" + second);
//		System.out.println("现在几毫秒:" + millisecond);
//		System.out.println("本月最后一天是:" + maxDate);
//		// 表示本周的第几天，从周日开始计算
//		System.out.println("firstDay:" + firstDay);
        String orderCode = year + "" + month + "" + date + "" + dayOfWeek + "" + dayOfYear + "" + hour + "" + minute + "" + second + "" + millisecond + "" + firstDay;
        System.out.println("orderCode = " + orderCode);
        return orderCode;
    }
}